package com.doradance.view.status;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.doradance.R;


/**
 * Description:
 * Author:yong
 * Date:2017-12-21
 */

public class RefreshPageView implements StatusView {
    private ImageView ivLoading;
    private MaterialProgressDrawable mProgressDrawable;

    @Override
    public final View onCreateStatusView(LayoutInflater inflater, ViewGroup parent) {
        View view = inflater.inflate(R.layout.layout_status_refresh_default, parent, false);
        Context context = view.getContext();
        ivLoading = (ImageView) view.findViewById(R.id.iv_refresh);
        mProgressDrawable = new MaterialProgressDrawable(context, ivLoading);
        mProgressDrawable.updateSizes(MaterialProgressDrawable.DEFAULT);
        mProgressDrawable.setBackgroundColor(0xFFFAFAFA);
        mProgressDrawable.setColorSchemeColors(ContextCompat.getColor(context, R.color.loading));
        return view;
    }

    @Override
    public final void onStatusViewCreated() {

    }

    @Override
    public final int getStatus() {
        return ViewConstant.VIEW_STATUS_REFRESH;
    }

    @Override
    public final void onViewAttachedToWindow() {
        mProgressDrawable.setProgressRotation(0.8f);
        mProgressDrawable.setStartEndTrim(0f, 0.5f);
        mProgressDrawable.setAlpha(255);
        mProgressDrawable.start();
    }

    @Override
    public final void onViewDetachedFromWindow() {
        mProgressDrawable.stop();
    }
}
